/**
 * Created by lanyanhua on 2018/10/31 0031.
 */
NProgress.start();
window.onload = function () {
    NProgress.done();
};
layui.use(['element', 'table', 'form', 'jquery', 'laydate', 'list'], function () {
    var table = layui.table;
    var form = layui.form;
    var $ = layui.jquery;
    var list = layui.list;

    var showdatatable = table.render({
        elem: '#tableId',
        id: "showdata",
        url: '/log/findJobLogAll',
        limit: 10,
        page: true,
        while: param(),
        cols: [[
            {type: 'checkbox'},
            {field: 'jobName', title: '名称', width: 130},
            {field: 'message', title: '消息', templet: '#roleTpl', width: 260},
            {
                field: 'startTime',
                title: '开始执行时间',
                width: 260,
                templet: '<div>{{ Format(d.startTime,"yyyy-MM-dd hh:mm:ss")}}</div>'
            },
            {
                field: 'endTime',
                title: '结束时间',
                width: 260,
                templet: '<div>{{ Format(d.endTime,"yyyy-MM-dd hh:mm:ss")}}</div>'
            },
            {field: 'logId', title: 'ID', sort: true, width: 60},
            {field: 'jobGroup', title: '项目名', width: 130},
            {field: 'cronExpression', title: 'cron 表达式', width: 115},
            {field: 'executeAddress', title: '执行地址', width: 245},
            {field: 'success', title: '执行结果', hide: true, width: 90},
            {field: 'errorCode', title: '状态码', width: 80, templet: '#roleTpl'},
            {title: '操作', templet: '#operationTpl', width: 100, align: 'center', fixed: 'right'}
        ]]

    });
    var listOpen = {
        elem: "#test6",
        readonly: "readonly",
        fields: {
            jobName: {label: "名称" }
            , jobGroup: {label: "项目名"}
            , cronExpression: {label: "cron表达式"}
            , executeAddress: {label: "执行地址"}
            , success: {label: "执行结果"}
            , errorCode: {label: "状态码"}
            , message: {label: "消息"}
            , startTime: {label: "开始执行时间"}
            , endTime: {label: "结束时间"}
        },
        btns: ["submit", 'reset'],
        area: ['80%', '90%']
    };
    form.on('submit(search)', function () {
        showdatatable.reload({where: param()});
        return false;
    });

    table.on('tool(tableFilter)', function (obj) {
        var data = obj.data;
        var layEvent = obj.event;
        if (layEvent === 'edit') {
            //console.log(data);updateJob
            data.success = data.success ? "成功" : "失败";
            data.startTime = Format(data.startTime, "yyyy-MM-dd hh:mm:ss");
            data.endTime = Format(data.endTime, "yyyy-MM-dd hh:mm:ss");
            listOpen.over = data;
            list.open(listOpen);
        }
    });

    function param() {
        return {
            jobName: $('[name=jobName]').val(),
            jobGroup: $('[name=jobGroup]').val()
        }
    }
});
